package com.ouryue.test.controller;

import java.util.ArrayList;
import java.util.List;

import org.light.framework.bean.PageArgs;
import org.light.framework.bean.ResultOrder;
import org.light.framework.bean.SearchArgs;
import org.light.framework.mvc.RequestParam;
import org.light.framework.mvc.View;
import org.light.framework.mvc.annotation.Action;
import org.light.framework.mvc.annotation.Controller;
import org.light.framework.mvc.annotation.Inject;
import org.light.framework.mvc.annotation.RequestMethod;
import org.light.framework.util.ReflectionUtil;

import com.ouryue.test.bean.User;
import com.ouryue.test.service.IUserService;


@Controller
public class UserController {

	@Inject
	IUserService comp;

	@Action("/index")
	public View index(RequestParam params) {
		
		
		SearchArgs searchArgs=new SearchArgs();
		PageArgs pageArgs=new PageArgs();
		ResultOrder resultOrder=new ResultOrder();
		
		List<User> userList = new ArrayList<User>();//comp.search(User.class, searchArgs, pageArgs, resultOrder);
		return new View("index.jsp").addModel("userList", userList);
	}

	@Action(method=RequestMethod.POST,value="/user_create")
	public View user_create(RequestParam params) throws Exception {

		User obj = new User();

		try {
			ReflectionUtil.setPropertyValue(obj, params.getFieldMap());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		comp.test(obj);
		return new View("index.jsp").addModel("user", obj);
	}

	@Action("/user")
	public View user_detail(RequestParam params) {
		User model = comp.get(User.class, "430266bf-3535-473b-8ce0-00f2a7a0db37");
		return new View("user.jsp").addModel("user", model);
	}

}
